package com.open.capacity.common.util.skf;

public class skf_test_demo {

    public static void main(String[] args) {
        String text_plain = "123测试原文";       // 问题：汉字原文做sm3后的结果，与xtx控件做sm3的结果，不一致!
        text_plain = "123test1";
        System.out.println("text_plain = " + text_plain);

        String USER_PIN = "111111";
        Util.debug(true);

        SKF_TOOL skf = new SKF_TOOL(USER_PIN);

        String[] charsetname = {"Unicode","utf-16","utf-8","gbk","gb2312","GB18030","ASCII","ISO-8859-1"};
        for( int i =0;i<charsetname.length;i++){
            String sm3_no_userid = skf.sm3_no_userid(text_plain, charsetname[i]);
            System.out.println("sm3_no_userid = " + sm3_no_userid + " " + charsetname[i]);
        }

        String sm3_no_userid = skf.sm3_no_userid(text_plain);
        System.out.println("sm3_no_userid = " + sm3_no_userid );

        String sm3_with_userid = skf.sm3_with_userid(text_plain);
        System.out.println("sm3_with_userid = " + sm3_with_userid);

        //String cert = get_cert();
        // System.out.println("cert = " + cert);

        String sign_p1 = skf.sign_p1(text_plain, USER_PIN);
        System.out.println("sign_p1 = " + sign_p1);

        long startTime=System.currentTimeMillis();   //获取开始时间
        for(int i=0;i<51;i++) {
            sign_p1 = skf.sign_p1(text_plain, USER_PIN);
            System.out.println(i + " sign_p1 = " + sign_p1);
        }
        long endTime=System.currentTimeMillis(); //获取结束时间
        System.out.println("程序运行时间： "+(endTime-startTime)+"ms");

        //text_plain = "123test1篡改了";
        //sign_p1 = "MEUCIFQbP1fYfIeQZlYqb8q4qQ0FWPvMS+3zXy50jDC3vpEmAiEAqf4G/Aq2xw6MVsMHP4HsrP7K0PJSedGOdh8qlDPRxv8=";
        int verify_p1 = skf.verify_p1( text_plain, sign_p1);
        System.out.println("verify_p1 = " + verify_p1);

        // 释放ukey资源
        skf.close();
    }

}
